<%@ page language="java" import="com.ruohi.util.common.CommonForm,com.ruohi.util.common.Env" pageEncoding="UTF-8" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.TreeMap" %>
<%
	String tableName = "gift_tuan";
	String tablePrefix = Env.getInstance().getProperty("table_prefix");
	String fileds = "id,add_date,uuid,product_no,tuan_title,tuan_intro,tuan_price,storage,max_buy_count,tuan_virtual_number,tuan_number,begin_time,end_time,is_show,is_advance,(select name from gift_product where gift_product.no=gift_tuan.product_no) as product_name";
	String whereStr = " ";
	String orderByStr = " id desc ";
	
	Map statusMap = new TreeMap();
	statusMap.put("", "-请选择-");
	statusMap.put("1", "是");
	statusMap.put("0", "否");
	statusMap.put("2", "下期团购");
	statusMap.put("3", "顶部推荐");
	
	Map advanceMap = new TreeMap();
	advanceMap.put("", "-请选择-");
	advanceMap.put("0", "否");
	advanceMap.put("1", "是");
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
  </head>
  <body>
  	<div class="searchForm">
  		<div class="searchCondition">
            <div class="searchList">
		  		<div class="searchLeft">是否显示</div>
		  		<div class="searchRight">
		  			<select id="is_show" name="is_show" class="jr_select">
		  				<%=CommonForm.createSelect(statusMap, "") %>
		  			</select>
		  		</div>
		  	</div>
		  	<div class="searchList">
		  		<div class="searchLeft">是否预售</div>
		  		<div class="searchRight">
		  			<select id="is_advance" name="is_advance" class="jr_select">
		  				<%=CommonForm.createSelect(advanceMap, "") %>
		  			</select>
		  		</div>
		  	</div>
  		</div>
  		<div class="searchBtn">
  			<input type="button" class="btn" onclick="doSearch();" value="查询" /><input type="button" style="margin-left: 5px;" class="btn" onclick="doClearForm();" value="重置" />
  		</div>
  	</div>
  	<div style="clear: left;"></div>
  	
	<div class="l-loading" style="display: block" id="pageloading"></div> 
	<div id="maingrid" style="margin: 0; padding: 0"></div>
	<div style="display: none;"></div>
  </body>
</html>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/plugin/date/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" prefix="<%=tablePrefix %>" type="text/javascript"></script>
<script type="text/javascript">
	var grid;
	var windowWidth = 700;
	var windowHeight = 240;
	var channelUUID = "";
	var tableName = "<%=tableName %>";
	var fields = "<%=fileds %>";
	var whereStr = "<%=whereStr %>";
	var orderBy = "<%=orderByStr %>";
	var columnsArr = [];
	var url = "";
	var conditionStr = "";
	var params = [];
	jQuery(function() {
		params.push({'name':'enumNo','value':'106013'});
		grid = new Dev21sunGrid();
		jQuery("#pageloading").hide();
	});
	var is_showData = [{ is_show : 1 , text: '是' }, { is_show : 0 , text: '否'}];
	//列数组
	columnsArr =  [
		{ display:"操作", align:"center", width:120, render:function(row){
			return "<a class='link' href='javascript:void(0);' onclick='addAndEdit("+row.__index+");'>编辑</a>" + (row.is_show == 1||row.is_show==3 ? "&nbsp;&nbsp;<a class='link' href='javascript://void(0);' onclick='send_tuan_alert(\"" + row.begin_time + "\");'>发送提醒邮件</a>" : "");
		} },
		{ display:"开始时间-结束时间", align:"left", type:"string", width:260, render:function(row){
			return row.begin_time.substring(0,row.begin_time.length-2) + " - " + row.end_time.substring(0,row.end_time.length-2);
		} },
		{ display : '团购产品', name : 'product_name', align : 'left' , type : 'string' , width : 180, render:function(row){
            return "<a target='_blank' href='http://www.52sdskj.com/product/" + row.product_no + ".htm'><img class='preview' src='/plugin/ui/ligerUI/ligerUI/skins/icons/preview.png' /></a>" + row.product_name;
		} }  ,
		{ display : '团购标题', align : 'left' , type : 'string' , width : 180, render:function(row){
			return row.tuan_title=="" ? row.product_name : row.tuan_title;
		} },
		{ display:"团购简介", name:"tuan_intro", align:"left", type:"string", width:180 },
		{ display:"团购价", align:"center", type:"string", width:75, render:function(row){
			return row.tuan_price.toFixed(1);
		} },
		{ display:"库存量", name:"storage", align:"center", type:"int", width:80 },
		{ display:"限购数量", name:"max_buy_count", align:"center", type:"int", width:80 },
		{ display:"虚拟参团人数", name:"tuan_virtual_number", align:"center", type:"int", width:100 },
		{ display:"实际参团人数", name:"tuan_number", align:"center", type:"int", width:100 },
		{ display:"是否显示", name:"is_show", align:"center", type:"int", width:80, render:function(row){
			var str = "";
			switch(row.is_show){
				case 0:
					str = "否";
				break;
				case 1:
					str = "是";
				break;
				case 2:
					str = "下期团购";
				break;
				case 3:
					str = "顶部推荐";
				break;
			}
			return str;
		} },
		{ display:"是否预售", name:"is_advance", align:"center", type:"int", width:80, render:function(row){
			return row.is_advance==1 ? "是" : "否";
		} }
	];
	
	/*列表页条件查询*/
	function doSearch(){
		params = [];
		conditionStr = "";
		var is_show = jQuery("#is_show").val();
		if(''!=jQuery.trim(is_show)){
			conditionStr += " and is_show = " + is_show;
		}
		var is_advance = $.trim($("#is_advance").val());
		if(is_advance != ""){
			conditionStr += " and is_advance=" + is_advance;
		}
		params.push({'name':'enumNo','value':'106013'});
		params.push({'name':'tableName','value':tableName});
		params.push({'name':'fields','value':fields});
		params.push({'name':'whereStr','value':whereStr+conditionStr});
		params.push({'name':'orderBy','value':orderBy});
		grid.options.parms=params;
		grid.loadData();
	}
	
	function addAndEdit(index){
		if(undefined==index){//如果是增加
			toolbarAdd({
				width:700,
				height:600,
				title:"增加"
			});
		}else{//如果是修改
	    	var row = grid.getRow(index);
	    	toolbarAdd({width:700,height:600,title:'编辑'},row.uuid);
		}
    }
    
    function send_tuan_alert(begin_time){
    	jrConfirm("确定要发送团购提醒吗？", function(v) {
			if (v) {
				$.ajax({
		    		type:"post",
		    		url:"/backend/action/ajax_r.jsp",
		    		data:{flag:"sendTuanAlert",begin_time:begin_time,enumNo:"106013"}
		    	});
		    	jrSuccess("已发送！");
			}
		});
    }
</script>